{template 'common/header'}
<style>
	.main{
		margin: 0 0 30px 0;
	}
</style>
<ul class="nav nav-tabs">
	<li {if $operation == 'index'}class="active"{/if}><a href="{php echo $this->createWebUrl('card', array('op' => 'index'))}">卡片列表</a></li>
	<li {if $operation == 'post'}class="active"{/if}><a href="{php echo $this->createWebUrl('card', array('op' => 'post'))}">添加卡片</a></li>
	
</ul>
{if $op == 'index'}
<div class="main">
    <div class="panel panel-default">
        <div class="table-responsive panel-body">
            <form action="" method="post" class="form-horizontal form" onsubmit="return formcheck(this)">
                <table class="table table-hover" style="margin-top: 15px;">
                    <thead class="navbar-inner">
                    <tr>
                    	<th class="text-center" style="width:10%;">编号</th>
                    	<th class="text-center" style="width:20%;">缩略图</th>
                    	<th class="text-center" style="width:30%;">卡片名称</th>
                    	<th class="text-center" style="width:20%;">所属银行</th>
                        <th class="text-right"  style="width:20%;">操作</th>
                    </tr>
                    </thead>
                    <tbody id="level-list">
                    {loop $list $row}
                    <tr>
                    	<td class="text-center">{$row['id']}</td>
						<td class="text-center">
							<img src="{$_W['attachurl']}{$row['photo']}" style="width:45px;height:30px" />
						</td>
						<td class="text-center">{$row['title']}</td>
						<td class="text-center">{php echo $this->bank($row['bank'])['name']}</td>
                        <td style="text-align:right;">
                            <a class="btn btn-default btn-sm" href="{php echo $this->createWebUrl('card', array('op' => 'post', 'id' => $row['id']))}" title="编辑"><i class="fa fa-pencil"></i></a>
                            <a class="btn btn-default btn-sm" onclick="return confirm('是否要删除？');return false;" href="{php echo $this->createWebUrl('card', array('op' => 'delete', 'id' => $row['id']))}" title="删除"><i class="fa fa-times"></i></a>
                        </td>
                    </tr>
                    {/loop}
                    <tr>
                        <td colspan="6">
                            <input type="hidden" name="token" value="{$_W['token']}"/>
                        </td>
                    </tr>
                    </tbody>
                </table>
                
				<div class="pull-right">
					{$pager}
				</div>
                
            </form>
        </div>
    </div>
</div>
{elseif $op == 'post'}
<div class="main">
	<form action="" method="post" class="form-horizontal form" >
    <div class="panel panel-default">
        <div class="panel-heading">管理卡片 </div>
        <div class="panel-body">   
            <div class="form-group">
                <label class="col-xs-12 col-sm-3 col-md-2 control-label">卡片名称</label>
                <div class="col-sm-9">
                    <input type="text" name="title" class="form-control title" value="{$item['title']}" />
                </div>
            </div>
            
            <div class="form-group">
                <label class="col-xs-12 col-sm-3 col-md-2 control-label">所属银行</label>
                <div class="col-sm-9">
                    <select type="text" name="bank" class="form-control bank">
                    	{loop $banks $row}
                    	<option value="{$row['id']}" {if $item['bank'] == $row['id']}selected{/if} >{$row['name']}</option>
                    	{/loop}
                    </select>
                </div>
            </div>
            
            <div class="form-group">
                <label class="col-xs-12 col-sm-3 col-md-2 control-label">缩略图片</label>
                <div class="col-sm-9">
            		{php echo tpl_form_field_image('photo',$item['photo'], '/web/resource/images/nopic.jpg', array('width' => 640, 'height' => 320))}
                </div>
            </div>
            
			<div class="form-group">
				<label class="col-xs-12 col-sm-3 col-md-2 control-label">简要描述</label>
				<div class="col-xs-9">
					<textarea class="form-control desc" name="desc" rows="5" style="100%" />{$item['desc']}</textarea>
				</div>			
			</div>
            <div class="form-group">
                <label class="col-xs-12 col-sm-3 col-md-2 control-label">详细描述</label>
                <div class="col-xs-9">
                    <textarea class="form-control detailed" name="detailed" rows="5">{$item['detailed']}</textarea>
                </div>          
            </div>
			<div class="form-group">
                <label class="col-xs-12 col-sm-3 col-md-2 control-label">是否推荐</label>
                <div class="col-xs-9">
                    <input type="radio" name="recommend" value="1" {if $item['recommend']==1}checked="checked"{else}checked="checked"{/if}>不推荐
                    <input type="radio" name="recommend" value="2"{if $item['recommend']==2}checked="checked"{/if}>推荐

                </div>          
            </div>
            <div class="form-group">
                <label class="col-xs-12 col-sm-3 col-md-2 control-label">API地址</label>
                <div class="col-sm-9">
                    <input type="text" name="api" class="form-control api" value="{$item['api']}" />
                </div>
            </div>
			

        </div>
    </div>
    <div class="form-group">
        <div class="col-sm-12">
            <input name="submit" type="submit" value="提交" class="btn btn-primary ">
            <input type="hidden" name="token" value="{$_W['token']}"/>
			<input type="hidden" name="id" value="{$item['id']}"/>
        </div>
    </div>
	</form>
</div>
<script>
require(['util'],function(util){
    util.editor( $(".detailed")[0]);


});
require(['jquery', 'util'], function($, util){
    $(function(){
        $('form').submit(function(){
           var title=$(".title").val();
            if(title==''||title==null){
                util.message('请填写卡片名称');
                return false;
            }
           var bank=$(".bank").val();
            if(bank==''||bank==null){
                util.message('请填写所属银行');
                return false;
            }
            var desc=$(".desc").val();
            if(desc==''||desc==null){
                util.message('请填写简要描述');
                return false;
            }
            var api=$(".api").val();
            if(api==''||api==null){
                util.message('请填写api网址');
                return false;
            }
        });

    });

});
</script>

{/if}

{template 'common/footer'}